
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>收货地址</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/site.css" />
		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">
		<!-- 引入组件 -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@1.6/lib/vant.min.js"></script>
	</head>
	<body>
		<div id="app">
			<!-- 头部 -->
			<van-nav-bar id="S_bar" fixed=true title="收货地址" right-text="删除" left-arrow @click-left="onClickLeft" @click-right="onClickRight"></van-nav-bar>
			<!-- 内容 -->
			<!-- 底部 -->
			<van-address-list v-model="chosenAddressId" :list="list" add-button-text="新增地址" @add="onAdd" @edit="onEdit"></van-address-list>
		</div>
		<script src="js/ajax.js"></script>
		<script src="html5plus://ready"></script>
		<script>
			var app = new Vue({
				el: "#app",
				data: {
					chosenAddressId: 0,
					list: []
				},
				methods: {
					onAdd() {
						plus.webview.show(plus.webview.create("site_add.html", "site_add"),"slide-in-left")
					},
					onClickLeft() {
						plus.webview.close(plus.webview.currentWebview());
					},
					onClickRight() {
						var _this = this;
						if (confirm('是否删除') == true) {
							// 获取选中的下标   this.list[this.chosenAddressId]
							ajax({
								url: "http://dsapi.ysd3g.com/api/DeleteShippingAddress",
								data: {
									key: localStorage.getItem('Key'),
									addressId: _this.list[_this.chosenAddressId].arrid
								},
								dataType: "jsonp",
								success: function(res) {
									if (!res.Error) {
										alert("删除成功")
										plus.webview.getWebviewById("site").reload(true);
									} else {
										alert(res.Msg)
									}
								}
							})
						} else {
							alert("已取消")
						}
					},
					onEdit(item, index) {
						plus.webview.show(plus.webview.create("site_xg.html", "site_xg",{}, {arrid:item.arrid}),"slide-in-bottom");
					}
				},
				mounted() {
					var _this = this
					ajax({
						url: "http://dsapi.ysd3g.com/API/MyShippingAddressList",
						data: {
							key: localStorage.getItem('Key')
						},
						dataType: "jsonp",
						success: function(res) {
							if (!res.Error) {
								var count = 0;
								for (var i = 0; i < res.Data.length; i++) {
									var obj = {};
									obj.id = count++,
									obj.name = res.Data[i].name
									obj.tel = res.Data[i].tel
									obj.address = res.Data[i].address
									obj.arrid = res.Data[i].id
									_this.list.push(obj)
								}
							} 
						}
					})
				}
			})
		</script>
	</body>
</html>
